package com.gexiaobao.pigeon.ui.adapter

import androidx.appcompat.widget.AppCompatImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.GatherLiveResponse
import com.gexiaobao.pigeon.app.util.ImageLoaderManager
import com.gexiaobao.pigeon.databinding.ItemLiveGatherBinding

/**
 * @Author      : hxw
 * @Date        : 2024/8/22 17:20
 * @Describe    :
 */
class GatherLiveListAdapter(data: ArrayList<GatherLiveResponse.GatherLiveBean.ChannelListBean>) :
    BaseQuickAdapter<GatherLiveResponse.GatherLiveBean.ChannelListBean, DataBindBaseViewHolder>(R.layout.item_live_gather, data) {

    private var mOnItemClickListener: OnItemClickListener? = null

    override fun convert(holder: DataBindBaseViewHolder, item: GatherLiveResponse.GatherLiveBean.ChannelListBean) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemLiveGatherBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动
        val ivCover = holder.getView<AppCompatImageView>(R.id.ivCoverGather)

        ImageLoaderManager.loadRoundImageOrEmpty(context, item.snapshot, ivCover, 12, R.mipmap.app_icon_)

        holder.itemView.setOnClickListener {
            mOnItemClickListener?.onItemClick(holder.layoutPosition, item)
        }
    }

    fun setOnItemClickListener(listener: OnItemClickListener?) {
        mOnItemClickListener = listener
    }

    interface OnItemClickListener {
        fun onItemClick(position: Int, data: GatherLiveResponse.GatherLiveBean.ChannelListBean)
    }
}